﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;

namespace 包覆门.KaikongManager
{
    public partial class KaikongList : Form
    {
        public KaikongList()
        {
            InitializeComponent();
            this.dgKkfx.AutoGenerateColumns = false;//限定展示列表
        }
        private KaikongDAL dal = new KaikongDAL();
        //新增
        private void tsbAdd_Click(object sender, EventArgs e)
        {
            KaikongEditing ke = new KaikongEditing();
            ke.IsNew = true;
            if (ke.ShowDialog() == DialogResult.OK) {
                LoadData();
            }
        }
        //编辑
        private void tsbEdit_Click(object sender, EventArgs e)
        {
            int count = this.dgKkfx.SelectedRows.Count;
            if (count <= 0)
            {
                MessageBox.Show("请选择要编辑的行");
                return;
            }
            else {
                KaikongEditing ke = new KaikongEditing();
                ke.IsNew = false;
                ke.EditingId = this.dgKkfx.SelectedRows[0].Cells["kid"].Value.ToString();
                if (ke.ShowDialog() == DialogResult.OK)
                {
                    LoadData();
                }
                
            }
        }
        //删除
        private void tsbDel_Click(object sender, EventArgs e)
        {
             int count = this.dgKkfx.SelectedRows.Count;
            if (count <= 0)
            {
                MessageBox.Show("请选择要删除的行");
                return;
            }
            string kid = this.dgKkfx.SelectedRows[0].Cells["kid"].Value.ToString();
            string info = "你确定要删除:"+this.dgKkfx.SelectedRows[0].Cells["direction"].Value.ToString()+"么";
            if (dal.DelById(kid) == 1)
            {
                MessageBox.Show("删除成功");
                LoadData();
            }
            else {
                MessageBox.Show("删除失败");
            }
        }
        //关闭
        private void tsbClose_Click(object sender, EventArgs e)
        {
            Close();
        }
        //加载数据
        private void KaikongEditing_Load(object sender, EventArgs e)
        {
            LoadData();
        }
        //关闭前操作
        private void KaikongEditing_FormClosing(object sender, FormClosingEventArgs e)
        {
            mainform.kl = null;
        }
        //开孔方向数据列表
        public void LoadData() {
            string dirction = this.tbdirection.Text.Trim();
            this.dgKkfx.DataSource = dal.ListAll(dirction);
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            LoadData();
        }
    }
}
